/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __PONY_STTS22H_H__
#define __PONY_STTS22H_H__

/* includes (standard library, system) ---------------------------------------*/
#include <stdint.h>
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
#include <hal_i2c.h>
/* includes (local) ----------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/

#define STTS22H_ID 0xA0U

#define STTS22H_REG_WHOAMI         0x01U
#define STTS22H_REG_CTRL           0x04U
#define STTS22H_REG_STATUS         0x05U
#define STTS22H_REG_TEMP_L_OUT     0x06U
#define STTS22H_REG_TEMP_H_OUT     0x07U
#define STTS22H_REG_SOFTWARE_RESET 0x0CU

/* typedefs ------------------------------------------------------------------*/

typedef union {
    struct {
        uint8_t one_shot : 1;
        uint8_t time_out_dis : 1;
        uint8_t freerun : 1;
        uint8_t if_add_inc : 1;
        uint8_t avg : 2;
        uint8_t bdu : 1;
        uint8_t low_odr_start : 1;
    } bits;
    uint8_t byte;
} stts22h_ctrl_t;

typedef union {
    struct {
        uint8_t busy : 1;
        uint8_t over_thh : 1;
        uint8_t under_thl : 1;
        uint8_t not_used_01 : 5;
    } bits;
    uint8_t byte;
} stts22h_status_t;

typedef union {
    struct {
        uint8_t not_used_01 : 1;
        uint8_t sw_reset : 1;
        uint8_t not_used_02 : 4;
        uint8_t low_odr_enable : 1;
        uint8_t not_used_03 : 1;
    } bits;
    uint8_t byte;
} stts22h_software_reset_t;

typedef enum {
    STTS22H_POWER_DOWN = 0x00,
    STTS22H_ONE_SHOT = 0x01,
    STTS22H_1Hz = 0x04,
    STTS22H_25Hz = 0x02,
    STTS22H_50Hz = 0x12,
    STTS22H_100Hz = 0x22,
    STTS22H_200Hz = 0x32,
} stts22h_odr_temp_t;

/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

extern uint8_t stts22h_read_id(hal_i2c_dev_t *dev);
extern int stts22h_read_temp(hal_i2c_dev_t *dev, int16_t *temp);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __PONY_STTS22H_H__ */
